<template>
<view class="container">
  <view class="qrcodeBox" :style="'margin-top:' + marginTop + 'rpx;'">
    <image :src="card_info.card_qrcode" class="qrcode"></image>
  </view>
  <view class="card_id">{{ card_info.show_card_code }}</view>
  <view class="card_info">{{ card_info.wx_param_arr.notice }}</view>
</view>
</template>

"<script>
import common from '../../utils/common.js'
var app = getApp();

export default {
  data() {
    return {
      mer_id: 0,
      marginTop: 200,
      card_info: {}
    };
  },

  onShareAppMessage: function () {},
  onReachBottom: function () {},
  onPullDownRefresh: function () {},
  onUnload: function () {},
  onHide: function () {},
  onShow: function () {},
  onReady: function () {},
  onLoad: function (options) {
    if (!options.mer_id) {
      options.mer_id = app.merchantOwn.mer_id;
    }

    var sysRes = wx.getSystemInfoSync();
    var pxUnit = 750 / sysRes.windowWidth;
    var marginTop = (sysRes.windowHeight * pxUnit - 662) / 2;
    this.setData({
      mer_id: options.mer_id,
      marginTop: marginTop
    });

    if (!app.globalData.userInfo) {
      var that = this; //调用应用实例的方法获取全局数据

      common.getUserInfo(function (userInfo) {
        if (!userInfo.phone) {
          wx.navigateTo({
            url: "../my/newnumber"
          });
        } else {
          that.setMainContent();
        }
      }, 'setting');
    } else {
      this.setMainContent();
    }
  },
  components: {},
  props: {},
  methods: {
    setMainContent: function () {
      common.post('Wxapp_merchant&a=merchant_card', {
        mer_id: this.mer_id
      }, "setRightContent", this);
    },
    setRightContent: function (result) {
      if (result.card_info.wx_card_code != '') {
        result.card_info.show_card_id = result.card_info.wx_card_code;
      } else {
        result.card_info.show_card_id = result.card_info.id;
      }

      result.card_info.show_card_code = result.card_info.show_card_id.replace(/(.{4})/g, "$1 ");
      console.log(result.card_info);
      result.card_info.card_qrcode = 'https://hf.pigcms.com/index.php?c=Recognition&a=get_own_qrcode&size=8&qrCon=' + result.card_info.show_card_id;
      this.setData({
        card_info: result.card_info
      });
      wx.hideToast();
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
page{
  background: white;
}
.container{
  text-align: center;
  font-size: 36rpx;
}
.qrcodeBox{
  width:500rpx;
  margin:0 auto;
}
.qrcodeBox image{
  width:500rpx;
  height:500rpx;
}
.card_id,.card_info{
  margin-top:20rpx;
}
</style>